
namespace SharpTalk.Core.Diagnostic
{
    using System;
    using System.Diagnostics;
    using System.Reflection;
    using System.Runtime.Serialization;

    /// <summary>
    /// Base class used to trace events
    /// </summary>
    [Serializable]
    [DataContract]
    public class Traceable : ITraceProvider
    {
        [field: NonSerialized]
        [field: IgnoreDataMember]
        private ITraceProvider _internalTrace;
        /// <summary>
        /// Obtains or defines the ITraceProvider instance to use
        /// </summary>
        public ITraceProvider TraceProvider 
        {
            get { return _internalTrace; }
            set { _internalTrace = value; }
        }
        /// <summary>
        /// Defines the SourceLevel
        /// </summary>
        /// <param name="level"></param>
        public void SetSourceLevel(SourceLevels level)
        {
            if (_internalTrace == null) return;
            _internalTrace.SetSourceLevel(level);
        }
        [DebuggerStepThrough]
        public virtual void TraceError(string message)
        {
            if (_internalTrace == null) return;
            _internalTrace.TraceError(message);
        }
        [DebuggerStepThrough]
        public virtual void TraceError(string format, params object[] args)
        {
            if (_internalTrace == null) return;
            _internalTrace.TraceError(format, args);
        }
        [DebuggerStepThrough]
        public virtual void TraceException(MethodBase method, Exception exception)
        {
            if (_internalTrace == null) return;
            _internalTrace.TraceException(method, exception);
        }
        [DebuggerStepThrough]
        public virtual void TraceException(MethodBase method, Exception exception, bool includeStack)
        {
            if (_internalTrace == null) return;
            _internalTrace.TraceException(method, exception, includeStack);
        }
        [DebuggerStepThrough]
        public virtual void TraceInfo(string message)
        {
            if (_internalTrace == null) return;
            _internalTrace.TraceInfo(message);
        }
        [DebuggerStepThrough]
        public virtual void TraceInfo(string format, params object[] args)
        {
            if (_internalTrace == null) return;
            _internalTrace.TraceInfo(format, args);
        }
        [DebuggerStepThrough]
        public virtual void TraceDebug(string message)
        {
            if (_internalTrace == null) return;
            _internalTrace.TraceDebug(message);
        }
        [DebuggerStepThrough]
        public virtual void TraceDebug(string format, params object[] args)
        {
            if (_internalTrace == null) return;
            _internalTrace.TraceDebug(format, args);
        }
        [DebuggerStepThrough]
        public virtual void TraceMethodCall(MethodBase method)
        {
            if (_internalTrace == null) return;
            _internalTrace.TraceMethodCall(method);
        }
        [DebuggerStepThrough]
        public virtual void TraceEvent(TraceEventType type, string message)
        {
            if(_internalTrace == null) return;
            _internalTrace.TraceEvent(type, message);
        }
        [DebuggerStepThrough]
        public virtual void TraceEvent(TraceEventType type, string format, params object[] args)
        {
            if (_internalTrace == null) return;
            _internalTrace.TraceEvent(type, format, args);
        }
        [DebuggerStepThrough]
        public virtual bool ShouldTrace(TraceEventType type)
        {
            return _internalTrace == null ? false : _internalTrace.ShouldTrace(type);
        }
    }
}